package com.szgz.platform.result;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse<T> {

	private boolean success;
	private int code;
	private String message;
	private T data;

	public ApiResponse() {}

	public ApiResponse(boolean success, int code, String message, T data) {
		this.success = success;
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public static <T> ApiResponse<T> success() {
		return new ApiResponse<>(true, 200, "OK", null);
	}

	public static <T> ApiResponse<T> success(T data) {
		return new ApiResponse<>(true, 200, "OK", data);
	}

	public static <T> ApiResponse<T> success(String message, T data) {
		return new ApiResponse<>(true, 200, message, data);
	}

	public static <T> ApiResponse<T> fail(String message) {
		return new ApiResponse<>(false, 400, message, null);
	}

	public static <T> ApiResponse<T> fail(int code, String message) {
		return new ApiResponse<>(false, code, message, null);
	}

	public boolean isSuccess() { return success; }
	public void setSuccess(boolean success) { this.success = success; }

	public int getCode() { return code; }
	public void setCode(int code) { this.code = code; }

	public String getMessage() { return message; }
	public void setMessage(String message) { this.message = message; }

	public T getData() { return data; }
	public void setData(T data) { this.data = data; }
}

